
$(function(){
    /*错误class  form-control is-invalid
    正确class  form-control is-valid*/
    var flagOldPass = false;
    var flagPas=false;
    var flagPass=false;
    var oldPassword = $("#oldPassword");
    var newPassword = $("#newPassword");
    var repeatPassword = $("#repeatPassword");
    var mes1 = $("#mes1");
    var mes2 = $("#mes2");
    var mes3 = $("#mes3");

    var passWord,passWords,oldPass;

    oldPassword.change(function(){
        oldPass = oldPassword.val();
        if(oldPass===""||(oldPass.length<6||oldPass.length>18)){
            mes3.removeClass("invalid-feedback");
            mes3.addClass("invalid-no");
            flagOldPass=false;
        } else{
            mes3.removeClass("invalid-no");
            mes3.addClass("invalid-feedback");
            flagOldPass=true;
        }
    });

    /*验证密码*/
    newPassword.change(function(){
        passWord=newPassword.val();
        if(passWord.length<6||passWord.length>18){
            mes1.removeClass("invalid-feedback");
            mes1.addClass("invalid-no");
            flagPas=false;
        }else{
            mes1.removeClass("invalid-no");
            mes1.addClass("invalid-feedback");
            flagPas=true;
        }
    });
    /*验证确认密码*/
    repeatPassword.change(function(){
        passWords=repeatPassword.val();
        if(((passWords!==passWord)||(passWords.length<6||passWords.length>18))){
            //console.log("不同");
            mes2.removeClass("invalid-feedback");
            mes2.addClass("invalid-no");
            flagPass=false;
        }else{
            mes2.removeClass("invalid-no");
            mes2.addClass("invalid-feedback");
            flagPass=true;
        }
    });


    $("#change_btn").click(function(){
        $("#error").css("display","none");
        //console.log(flagPas+" "+flagPass);
        if(flagPas&&flagPass&&flagOldPass){
            $.ajax({
                type:"get",
                url:"changeAdminPassWord",
                data:{
                    "account":$("#account").val(),
                    "oldPassword":oldPass,
                    "newPassword":passWords
                },
                success:function (data) {
                    if(data===0){
                        $("#error").css("display","block");
                    }else {
                        location.href="admin/login.html";
                    }
                }

            })
        }else{
            if(!flagOldPass){
                mes3.addClass("invalid-no");
            }
            if(!flagPas){
                mes1.addClass("invalid-no");
            }
            if(!flagPass){
                mes2.addClass("invalid-no");
            }
        }
    })
});

